#!/usr/bin/env python
# Create: 2018/10/12
__author__ = '749B'

import requests
from bs4 import BeautifulSoup

from utils.base64p import b64decode_str

session = requests.Session()

# 默认的 User-Agent 的值是 "python-requests" 会被反爬，需要改一下
session.headers['User-Agent'] = ""
session.get('https://dig.chouti.com')

# 不能把密码上传啊
with open('password/s2.txt') as f:
    auth = f.read()
    auth = auth.split('\n')

post_dict = {
    'phone': '86%s' % auth[0],  # 从请求正文里发现，会在手机号前加上86
    'password': b64decode_str(auth[1]),
}
session.post('https://dig.chouti.com/login', data=post_dict)

# 获取咨询，然后点赞
# r3 = session.get('https://dig.chouti.com')  # 默认首页
r3 = session.get('https://dig.chouti.com/r/scoff/hot/1')  # 段子
r3.encoding = r3.apparent_encoding
soup = BeautifulSoup(r3.text, features='html.parser')
target = soup.find(id='content-list')
item = target.find('div', {'class': 'item'})
news = item.find('a', {'class': 'show-content'}).text
linksId = item.find('div', {'class': 'part2'}).attrs['share-linkid']
print('news:', news.strip())

# 点赞
r = session.post('https://dig.chouti.com/link/vote?linksId=%s' % linksId)
print(r.text)





